<template>
  <div class="container">
    <el-dialog title="预览文章" :visible="flag" @close="handleClose()">
      <div class="main">
        <div class="head">
          <h3>{{ ruleForm.title }}</h3>
        </div>
        <div class="zn">
          <p>
            <span>{{ ruleForm.createTime }}</span> <span>{{ user }}</span>
            <span> <i class="el-icon-view" /></span
            ><span>{{ ruleForm.visits }}</span>
          </p>
        </div>
        <div class="fn">
          <p>{{ delHtmlTag(ruleForm.articleBody) }}</p>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { detail } from '@/api/hmmm/articles.js'
export default {
  props: {
    flag: {
      type: Boolean,
      default: false
    },
    preView: {
      type: Object
    }
  },
  data () {
    return {
      // ruleForm: {}
      form: { id: null, subjectID: null, directoryName: '' },
      ruleForm: { subjectID: '', directoryName: '' },
      user: ''
    }
  },
  methods: {
    delHtmlTag (str) {
      return str.replace(/<[^>]+>/g, '').replace(/$nbsp;/gi, '')
    },
    handleClose () {
      this.$emit('update:flag', false)
    },
    cancle () {
      this.handleClose()
    },
    getdetail () {
      this.$nextTick(async () => {
        const res = await detail(this.preView)
        this.ruleForm = res.data
        this.user = this.preView.username
      })
    }
  },
  created () {
    this.getdetail()
  }
}
</script>

<style scoped lang="less">
.el-dialog {
  width: 800px;
  .main {
    height: 184px;

    .zn {
      p {
        margin: 0;
        padding: 0;
      }
      span {
        margin-left: 10px;
      }
      margin-top: 20px;
      margin-bottom: 20px;
    }
    .fn {
      height: 80px;
      line-height: 80px;
      border-top: 1px dashed #ccc;
      background-color: #f5f5f5;
      p {
        margin: 0;
        padding: 0;
        margin-left: 10px;
      }
    }
  }
}
</style>
